package com.tech.sujay.android;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		ListView lv1 = (ListView) findViewById(R.id.listView1);
		ArrayList<String> items = new ArrayList<String>();
		items.add("abc");
		items.add("bcd");
		items.add("bgh");
		items.add("abc");
		items.add("bcd");
		items.add("bgh");
		items.add("abc");
		items.add("bcd");
		items.add("bgh");
		items.add("abc");
		items.add("bcd");
		items.add("bgh");
        MyAdapter adapter = new MyAdapter(this, R.layout.row, items);
        lv1.setAdapter(adapter);
        
		ListView lv2 = (ListView) findViewById(R.id.listView2);
		ArrayList<String> items2 = new ArrayList<String>();
		items2.add("yyy");
		items2.add("ooo");
		items2.add("uuu");
		items2.add("yyy");
		items2.add("ooo");
		items2.add("uuu");
		items2.add("yyy");
		items2.add("ooo");
		items2.add("uuu");
		items2.add("yyy");
		items2.add("ooo");
		items2.add("uuu");
        MyAdapter2 adapter2 = new MyAdapter2(this, R.layout.row2, items2);
        lv2.setAdapter(adapter2);
	}

	private class MyAdapter extends ArrayAdapter<String> {

		private ArrayList<String> items;

		public MyAdapter(Context context, int textViewResourceId,
				ArrayList<String> items) {
			super(context, textViewResourceId, items);
			this.items = items;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View v = convertView;
			if (v == null) {
				LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				v = vi.inflate(R.layout.row, null);
			}
			String o = items.get(position);
			if (o != null) {
				TextView tt = (TextView) v.findViewById(R.id.rowItem);
				if (tt != null) {
					tt.setText("Name: " + o);
				}
			}

			return v;
		}
	}

	private class MyAdapter2 extends ArrayAdapter<String> {

		private ArrayList<String> items2;

		public MyAdapter2(Context context, int textViewResourceId,
				ArrayList<String> items) {
			super(context, textViewResourceId, items);
			this.items2 = items;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View v = convertView;
			if (v == null) {
				LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				v = vi.inflate(R.layout.row2, null);
			}
			String o = items2.get(position);
			if (o != null) {
				TextView tt = (TextView) v.findViewById(R.id.rowItem2);
				if (tt != null) {
					tt.setText("Name2: " + o);
				}
			}

			return v;
		}
	}

}